<template>
  <div class="avatar">
    <div class="header">
      潮流头像库
    </div>
    <div class="main">
      <div>
        <!-- 通过风格种类来v-for -->
        <div class="avatardb">
          <div class="avatarson"  v-for="item in this.avatarlist" :key="item.index">
            <div
            @click="checkAv(item.url,item.index)"
            class="main"
            ><avatar size="40" :url="item.url"></avatar></div>
            <div class="avatarname">{{item.name}}</div>
            <i class="iconfont" v-if="item.index=== actid">&#xe66a;</i>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// 调用头像库接口渲染
import { getAvatardatabase } from '@/api/user'
// 引入头像组件来渲染
import avatar from '@/components/library/avatar.vue'
export default {
  name: 'edit-avatar',
  components: {
    avatar
  },
  data () {
    return {
      actid: '',
      avatarlist: [],
      checkAvatar: null
    }
  },
  methods: {
    checkAv (src, index) {
      this.checkAvatar = src
      this.actid = index
      // console.log(this.checkAvatar)
      // if (this.checkAvatar === src) {
      //   console.log(this.checkAvatar)
      // }
      this.$store.commit('user/updateAvatar', src)
    }
  },
  created () {
    getAvatardatabase().then(res => {
      // console.log(res.data.imglist)
      // console.log(typeof (res.data.imglist))
      this.avatarlist = res.data.imglist
    })
  }
}
</script>
<style scoped lang="less">
.avatar{
  margin: 0 auto;
  .header{
    height: 40px;
    line-height: 30px;
    font-family: '钉钉进步体';
    color: #666;
    font-size: 24px;
    display: flex;
      .header-item{
        cursor: pointer;
        margin-right: 20px; ;
        height: 20px;
        line-height: 20px;
        width: 100px;
      }
      .act{
        background-color: pink;
      }
  }
  .avatardb{
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    max-width: 560px;
    height: 100%;
    .avatarson{
      position: relative;
      width: 80px;
      height: 80px;
      .main{
        cursor: pointer;
        width: 40px;
        height: 40px;
        margin: 0 auto;
      }
      .avatarname{
        position: absolute;
        cursor: default;
        width: 80px;
        font-size: 10px;
        color: #666;
        text-align: center;
      }
      .iconfont{
        font-size: 40px;
        color: rgba(147, 229, 23, 0.482);
        position: absolute;
        top: 10px;
        left: 40%;
      }
    }
  }
}
</style>
